import Vue from 'vue'
import EventFilePreview from './EventFilePreview.vue'

const VueComp = Vue.extend(EventFilePreview)
let instance = null


const preview = {
    // 显示预览
    show(options) {
        options.onClose = preview.close
        if (!instance) {
          instance = new VueComp({ propsData: options })
        }
        const dom = document.createElement('div')
        document.body.appendChild(dom)
        instance.$mount(dom)
    },

    // 关闭
    close() {
        if (instance) {
            instance.$destroy()
            instance.$el && document.body.removeChild(instance.$el)
            instance = null
        }
    }
}

export default preview
